package org.jieshen.m1.d5;

public class Solution {
    public String modifyString(String s) {
        //26个英文字母
        char[] arr = new char[26];
        for (int i = 0; i < 26; i++) {
            arr[i] = (char) (97 + i);
        }
        for (int i = 0; i < s.length(); i++) {
            char left = ' ';
            char right = ' ';
            if (s.charAt(i) == '?') {
                if (i - 1 != -1) {
                    left = s.charAt(i - 1);
                }
                if (i + 1 != s.length()) {
                    right = s.charAt(i + 1);
                }

                for (char c : arr) {
                    if(c != left && c != right) {
                        s = s.substring(0, i) + c + s.substring(i + 1);
                        break;
                    }
                }
            }
        }
        return s;
    }

    /**
     * 输入：s = "??yw?ipkj?"
     * 输出："acywaipkja"
     * 输入：s = "j?qg??b"
     * 输出："jaqgacb"
     * 输入：s = "ubv?w"
     * 输出："ubvaw"
     */
    public static void main(String[] args) {
        String s = "ubvawa?";
        s = new Solution().modifyString(s);
//        s = s.substring(0, 0) + 'a' + s.substring(1);
        System.out.println(s);
    }
}
